﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ctrl : MonoBehaviour
{
    private Behavior behavior;

    public Joystick joystick;

    private bool isJump = false;

    // Start is called before the first frame update
    void Start()
    {
        behavior = gameObject.GetComponent<Behavior>();
    }

    // Update is called once per frame
    void Update()
    {
        if (!isJump) {
            for (int i=0; i< Input.touchCount; i++) {
                Vector3 pos = Input.GetTouch(i).position;
                if (pos.x > Screen.width / 2) {
                    isJump = true;
                    break;
                }
            }
        }
    }

    void FixedUpdate()
    {
        float x = joystick.Horizontal;
        behavior.Move(x);

        if (isJump) {
            behavior.Jump();
            isJump = false;
        }
    }
}
